<?php

namespace App\Http\Requests\Check;

use App\Http\Requests\BaseRequest;
use App\Models\Store;
use Illuminate\Foundation\Http\FormRequest;

class CheckStoreRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'id' => 'required|integer|exists:stores,id',
            'status' => 'required|integer|in:' . Store::STATUS_CHECK_FAIL . ',' . Store::STATUS_CHECK_SUCCESS,
        ];
        if ($this->get('status') == Store::STATUS_CHECK_FAIL) {
            $rules['opt_reason'] = 'required|min:10|max:200';
        }
        return $rules;
    }

    public function messages()
    {
        return [
            'status.required' => '请选择审核状态',
            'status.in'       => '所选状态不在范围内',
            'opt_reason.required' => '请输入拒绝理由',
            'opt_reason.min' => '拒绝理由不得少于10个字符',
            'opt_reason.max' => '拒绝理由不得超过200个字符',
        ];
    }
}
